package com.hgl.bi.common.exception;

import com.hgl.bi.common.model.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: BI
 * @description: 全局异常处理
 * @author: hgl
 * @create: 2025-02-09 17:01
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 异常处理器
     *
     * @param e 异常信息
     * @return R 统一返回体
     * @author hgl
     */
    @ExceptionHandler(BusinessException.class)
    public R<?> handleException(BusinessException e) {
        log.error("业务异常: {}", e.getMessage());
        return R.fail(e.getCode(), e.getMessage());
    }

}
